//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using NopSolutions.NopCommerce.BusinessLogic;
using NopSolutions.NopCommerce.BusinessLogic.CustomerManagement;
using NopSolutions.NopCommerce.BusinessLogic.Directory;
using NopSolutions.NopCommerce.Common.Utils;
using NopSolutions.NopCommerce.Common;
using NopSolutions.NopCommerce.BusinessLogic.Infrastructure;

namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class AccountEdit : BaseNopFrontendUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (IsNew)
                {
                  DoNew();
                }
            }
        }

        public void DoNew()
        {
          lblShippingAccountId.Text = string.Empty;
          txtFirstName.Text = string.Empty;
          txtPhoneNumber.Text = string.Empty;
          txtEmail.Text = string.Empty;
          txtFaxNumber.Text = string.Empty;
          txtCompany.Text = string.Empty;
          txtAddress1.Text = string.Empty;
          txtAddress2.Text = string.Empty;
          txtINN.Text = string.Empty;
          txtKPP.Text = string.Empty;
          txtOGRN.Text = string.Empty;
          txtBankName.Text = string.Empty;
          txtBankAddress.Text = string.Empty;
          txtBIK.Text = string.Empty;
          txtKorrAcc.Text = string.Empty;
          txtRS.Text = string.Empty;
        }

        public Address Account
        {
            get
            {
                var Account = new Address();
                if (!String.IsNullOrEmpty(lblShippingAccountId.Text))
                    Account.AddressId = int.Parse(lblShippingAccountId.Text);
                Account.FirstName = txtFirstName.Text.Trim();
                Account.LastName = "Account";
                Account.PhoneNumber = txtPhoneNumber.Text.Trim();
                Account.Email = txtEmail.Text.Trim();
                Account.FaxNumber = txtFaxNumber.Text.Trim();
                Account.Company = txtCompany.Text.Trim();
                Account.Address1 = txtAddress1.Text.Trim();
                Account.Address2 = txtAddress2.Text.Trim();

                Account.City = "Account";
                Account.CountryId = 1;
                Account.StateProvinceId = 1;
                Account.ZipPostalCode = "Account";

                Account.INN = txtINN.Text.Trim();
                Account.KPP = txtKPP.Text.Trim();
                Account.OGRN = txtOGRN.Text.Trim();
                Account.BankName = txtBankName.Text.Trim();
                Account.BankAddress = txtBankAddress.Text.Trim();
                Account.BIK = txtBIK.Text.Trim();
                Account.KorrAcc = txtKorrAcc.Text.Trim();
                Account.RS = txtRS.Text.Trim();
                Account.IsBillingAddress = true;
              
                return Account;
            }
            set
            {
                Address Account = value;
                if (Account != null)
                {
                    this.lblShippingAccountId.Text = Account.AddressId.ToString();
                    this.txtFirstName.Text = Account.FirstName;
                    this.txtPhoneNumber.Text = Account.PhoneNumber;
                    this.txtEmail.Text = Account.Email;
                    this.txtFaxNumber.Text = Account.FaxNumber;
                    this.txtCompany.Text = Account.Company;
                    this.txtAddress1.Text = Account.Address1;
                    this.txtAddress2.Text = Account.Address2;

                    this.txtINN.Text = Account.INN;
                    this.txtKPP.Text = Account.KPP;
                    this.txtOGRN.Text = Account.OGRN;
                    this.txtBankName.Text = Account.BankName;
                    this.txtBankAddress.Text = Account.BankAddress;
                    this.txtBIK.Text = Account.BIK;
                    this.txtKorrAcc.Text = Account.KorrAcc;
                    this.txtRS.Text = Account.RS;
                }
            }
        }

        [DefaultValue(-1)]
        public int AddressId
        {
          get
          {
            int result = -1;
            if (!String.IsNullOrEmpty(lblShippingAccountId.Text))
              result = int.Parse(lblShippingAccountId.Text);
            return result;
          }
        }
      
        [DefaultValue(true)]
        public bool IsNew
        {
            get
            {
                object obj2 = this.ViewState["IsNew"];
                return ((obj2 != null) && ((bool)obj2));

            }
            set
            {
                this.ViewState["IsNew"] = value;
            }
        }

        public string ValidationGroup
        {
            get
            {
                return txtFirstName.ValidationGroup;
            }
            set
            {
                txtFirstName.ValidationGroup = value;
                txtPhoneNumber.ValidationGroup = value;
                txtEmail.ValidationGroup = value;
                txtFaxNumber.ValidationGroup = value;
                txtCompany.ValidationGroup = value;
                txtAddress1.ValidationGroup = value;
                txtAddress2.ValidationGroup = value;

                txtINN.ValidationGroup = value;
                txtKPP.ValidationGroup = value;
                txtOGRN.ValidationGroup = value;
                txtBankName.ValidationGroup = value;
                txtBankAddress.ValidationGroup = value;
                txtBIK.ValidationGroup = value;
                txtKorrAcc.ValidationGroup = value;
                txtRS.ValidationGroup = value;
            }
        }
    }
}